﻿@model Madb.Site.Models.Documentation.Xml.Member
@{
	const int scrollOffset = -70;
}
<div class="member">
	@if(Model.Summary.Where(m => !string.IsNullOrWhiteSpace(m.Value)).Any()) {
		<div class="alert alert-success">
			@foreach(var s in Model.Summary) {
				if(!string.IsNullOrWhiteSpace(s.Value)) {
					<p class="man mbs pan">@Html.Raw(s)</p>
				}
			}
		</div>
	}

	@if(Model.Remarks.Where(m => !string.IsNullOrWhiteSpace(m.Value)).Any()) {
		<div class="alert alert-primary">
			@foreach(var s in Model.Remarks) {
				if(!string.IsNullOrWhiteSpace(s.Value)) {
					<p class="man mbs pan">@Html.Raw(s)</p>
				}
			}
		</div>
	}

	@if(Model.Gists.Where(m => !string.IsNullOrWhiteSpace(m.Id)).Any()) {
		<div class="gist-host">
			@foreach(var s in Model.Gists) {
				if(!string.IsNullOrWhiteSpace(s.Description)) {
					<div class="alert alert-primary">@s.Description</div>
				}
				<text>@Html.Action("Gist", new { controller = "Assets", id = s.Id })</text>
			}
		</div>
	}

	@if(Model.Params.Where(m => !string.IsNullOrWhiteSpace(m.Value)).Any()) {
		<h4 class="zero">Parameters</h4>
		<div class="mts">
			<table class="table table-bordered table-condensed table-striped">
				<tr>
					<th>Name</th>
					<th>Description</th>
				</tr>
				@foreach(var s in Model.Params) {
					if(!string.IsNullOrWhiteSpace(s.Name)) {
						<tr>
							<td>@s.Name</td>
							<td>@s.Value</td>
						</tr>
					}
				}
			</table>
		</div>
	}

	@if(Model.Exceptions.Any()) {
		<h4 class="zero">Exceptions</h4>
		<div class="mts">
			<table class="table table-bordered table-condensed table-striped">
				<tr>
					<th>Type</th>
					<th>Description</th>
				</tr>
				@foreach(var s in Model.Exceptions) {
					var reference = s.Link.Substring(2);
					var link = Url.ParseReferenceUrl(s.Link);
					var text = Url.ParseReferenceAsText(string.IsNullOrWhiteSpace(s.Description) ? s.Link : "{0}".With(s.Description));
					var regex = new System.Text.RegularExpressions.Regex(@"\sor\s", System.Text.RegularExpressions.RegexOptions.Multiline | System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
					foreach(var item in regex.Split(text)) {
						<tr>
							<td>
								@if(link.StartsWith("#")) {
									<a href="@link" data-scroll="click" data-scroll-offset="@scrollOffset">@reference</a>
								} else {
									<a href="@link" target="_blank">@reference</a>
								}
							</td>
							<td>@item</td>
						</tr>
					}
				}
			</table>
		</div>
	}

	@if(Model.SeeAlsos.Any() || Model.Sees.Any()) {
		<h4 class="zero">References</h4>
		<div class="mts">
			<table class="table table-bordered table-condensed table-striped">
				@foreach(var s in Model.SeeAlsos.Concat(Model.Sees)) {
					if(!string.IsNullOrWhiteSpace(s.Link)) {
						var text = Url.ParseReferenceAsText(string.IsNullOrWhiteSpace(s.Description) ? s.Link : s.Description);
						// process the link to internals.
						var link = Url.ParseReferenceUrl(s.Link);
						<tr>
							<td>
								@if(link.StartsWith("#")) {
									<a href="@link" data-scroll="click" data-scroll-offset="@scrollOffset">@text</a>
								} else {
									<a href="@link" target="_blank">@text</a>
								}
							</td>
						</tr>
					}
				}
			</table>
		</div>
	}
</div>